package com.baidu.shop.controller;

import com.baidu.shop.dto.SkuDTO;
import com.baidu.shop.dto.SpecGroupDTO;
import com.baidu.shop.dto.SpuDTO;
import com.baidu.shop.entity.SpuDetailEntity;
import com.baidu.shop.service.TemplatePageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @ClassName: PageController
 * @Author: User
 * @date: 2020.09.23 19:12
 * @version: 1.0
 */
@Controller
@RequestMapping("/item")
public class PageController {

    @Resource
    private TemplatePageService service;

    @GetMapping("/{spuId}.html")
    public String getSpu(@PathVariable("spuId") Integer spuId, ModelMap map){
        Map<String,Object> spuParam = service.getSpuParamById(spuId);
        map.addAttribute("spuInfo",(SpuDTO)spuParam.get("spuInfo"));
        map.addAttribute("spuDetail",(SpuDetailEntity)spuParam.get("spuDetail"));
        map.addAttribute("groupsInParams",(List<SpecGroupDTO>)spuParam.get("groupsInParams"));
        map.addAttribute("specParamMap",(Map<Integer, String>)spuParam.get("specParamMap"));
        map.addAttribute("skuList",(List<SkuDTO>)spuParam.get("skuList"));
        return "item";
    }

}
